<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>

<body style="font-family:Arial, Helvetica, sans-serif">
<form id="form1" name="form1" method="post" action="">
<h2>Job ID:<?php echo $this->jobId?></h2>
<?php $invCheck = 0;
	  $imeiCheck = 0;
	  $partsCheck = 0;
	  $rStaffCheck = 0;?>
	  
<h4>Change Quote (Optional)</h4>
<table width="600" border="1" cellspacing="0" cellpadding="15">
  <tr>
  	<th>Current Quote</th>
  	<?php if($this->quote != 0){?>
  	<td><?php echo "$ ".$this->quote?></td>
  	<?php }else{?>
  	<td><?php echo "$ 0.00"?></td>
  	<?php }?>
  </tr>
  <tr>
  	<th>New Quote</th>
  	<td>$ <input type = "text" name = "quote" ></input></td>
  </tr>
</table>
	  
<h4>Invoice Checker* <?php if($this->invoice1){ echo "<img src='/im/yes20.jpg' />"; }else{ echo "<img src='/im/no20.jpg' />";} ?></h4>
<table width="600" border="1" cellspacing="0" cellpadding="15">
  
  <tr>
  		<th>Invoice No:</th>
  		<td><?php echo $this->invoice1 ;?></td>	
  		<?php if($this->invoice1){
  				$invCheck = 1;
  		 }?>
  </tr>
  <tr>
  		<th>Add Invoice No:</th>
  		<td><input type = "text" name = "invoice" ></input> Input Full Invoice Id (L15xxxxxxx)</td>
  </tr>		
</table>

<h4>IMEI Checker*	<?php if($this->onScreenImei){ echo "<img src='/im/yes20.jpg' />"; }else{ echo "<img src='/im/no20.jpg' />";} ?></h4>
<table width="600" border="1" cellspacing="0" cellpadding="15">
  
  <tr>
    <td colspan="2" align="center">Since you have already fixed the device please <b style="color:red;">MUST</b> turn the Mobile on <br />
      and Press *#06# </td>
  </tr>
  <?php if(!$this->onScreenImei){?>
  <tr>
    <td>The On Device IMEI Is:<br />
    <span style=" font-size:10px;">(You may not change it)</span></td>
    <td>The On Screen IMEI Is<br />
      <span style=" font-size:10px;">(You may only input once)</span></td>
  </tr>
  <tr>
    <td><?php 
	if($this->mobile_imei == '000000000000000'){
		echo "NO DEVICE IMEI";
	}else{
		echo $this->mobile_imei;
	}	?> </td>
    <td><input type="text" name="on_screen_imei" id="on_screen_imei" style="width:200px;"/></td>
    </tr>
    <tr>
    	<td colspan = "2"><span id="imei_result" style = "color:red" >No IMEI Input</span></td>
    </tr>
    <?php }else{?>
    	<tr>
    		<td>The On Screen IMEI Is:</td>
    		<td><?php echo $this->onScreenImei?></td>
    	</tr>
    	<?php  $imeiCheck = 1;?>
    <?php }?>
</table>

<h4>Parts Checker* <?php if($this->partsRecord){ echo "<img src='/im/yes20.jpg' />"; }else{ echo "<img src='/im/no20.jpg' />";} ?></h4>
<table width="600" border="1" cellspacing="0" cellpadding="15">
	<?php if($this->partsRecord){
	$i = 1;?>
	<tr>
		<th colspan = "2">Parts Record</th>
	</tr>
		<?php foreach ($this->partsRecord as $k => $v){?>
		<tr>
			<td><?php echo $i++?></td>
			<td><?php echo $v?></td>
		</tr>

		<?php }?>
		<?php $partsCheck = 1;?>
	<?php }else{?>
		<tr>
			<td>No Parts Record</td>
			<td><a target="_blank" href="/repairparts/parts-record-with-borrow/shophead/<?php echo $this->shophead;?>/shop/<?php echo $this->shopId;?>/jobid/<?php echo $this->jobId;?>">Parts Record</a></td>
		</tr>
	<?php }?>
</table>

<h4>Repair Staff Check* <?php if($this->repairStaff){ echo "<img src='/im/yes20.jpg' />"; }else{ echo "<img src='/im/no20.jpg' />";} ?></h4>
<table width="600" border="1" cellspacing="0" cellpadding="15">
	<?php if($this->repairStaff){ ?>
		<tr>
			<th>Repair Staff:</th>
			<td><?php echo $this->repairStaff?></td>
		</tr>
		<?php $rStaffCheck = 1;?>
	<?php }else{?>
		<tr>
		<td>Input Password</td>
		<td><input type = "password" name = "tech_password"></input></td>
		</tr>
	<?php } ?>
</table>
<br/><br/>

<?php if($invCheck == 1 && $imeiCheck == 1 && $partsCheck == 1 && $rStaffCheck == 1){?>
		<input type = "submit" name = "close_job" value = "Close Job"></input>
<?php }else{?>
		<input type = "submit" name = "save_record" id = "btn_submitit" value = "Save Record/Change Status" <?php if(!$this->mobile_imei){?>disabled <?php }?>></input>
<?php }?>




</form>
<script language="javascript">

function isIMEI (s) {
var etal = /^[0-9]{15}$/;
  if (!etal.test(s))
    return false;
  if(s.indexOf('11111')>=0)
  	return false;  
  if(s.indexOf('22222')>=0)
  	return false; 
  if(s.indexOf('33333')>=0)
  	return false; 
  if(s.indexOf('44444')>=0)
  	return false;
  if(s.indexOf('55555')>=0)
  	return false; 
  if(s.indexOf('66666')>=0)
  	return false; 
  if(s.indexOf('77777')>=0)
  	return false; 
  if(s.indexOf('88888')>=0)
  	return false; 
  if(s.indexOf('99999')>=0)
  	return false; 
  if(s.indexOf('00000')>=0)
  	return false; 
	
	var str1 = '01234567890';
	var str2 = '09876543210';
	
	for(var i = 0; i < 5; i++){
		var substr = str1.substr(i,5);
		if(s.indexOf(substr)>=0)
		return false;		
	}
	for(var i = 0; i < 5; i++){
		var substr = str2.substr(i,5);
		if(s.indexOf(substr)>=0)
		return false;		
	}
  			
	
  sum = 0; mul = 2; l = 14;
  for (i = 0; i < l; i++) {
    digit = s.substring(l-i-1,l-i);
    tp = parseInt(digit,10)*mul;
    if (tp >= 10)
         sum += (tp % 10) +1;
    else
         sum += tp;
    if (mul == 1)
         mul++;
    else
         mul--;
    }
  chk = ((10 - (sum % 10)) % 10);
  if (chk != parseInt(s.substring(14,15),10))
    return false;
  return true;
}


$("#on_screen_imei").change(function(){
	
		var checkImei = $("#on_screen_imei").val();
		if(isIMEI(checkImei)){
			
			
			$("#imei_result").html("IMEI Check Pass");
			document.getElementById('btn_submitit').removeAttribute("disabled");
			
			} 
		else{
			$("#imei_result").html("Invalidated IMEI!!");
			document.getElementById('btn_submitit').setAttribute("disabled","disabled");
			}		
	});	
	

</script>
</body>

</html>
